package cn.com.mrzheng.web.controller;

import cn.com.mrzheng.web.controller.base.BaseController;
import cn.com.mrzheng.web.entity.Auth;
import cn.com.mrzheng.web.entity.Role;
import cn.com.mrzheng.web.entity.User;
import cn.com.mrzheng.web.mapper.user.IUserMapper;
import cn.com.mrzheng.web.server.impl.RoleService;
import cn.com.mrzheng.web.server.impl.UserService;
import cn.com.mrzheng.web.utils.AutoKey;
import cn.com.mrzheng.web.utils.Envelope;
import cn.com.mrzheng.web.utils.ServiceApi;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

// rest风格控制器
@RestController
//  跨域调用
@CrossOrigin(origins = ServiceApi.Config.CrossOrigin, maxAge = 3600)
public class LoginController extends BaseController<User, UserService> {

    @Autowired
    UserService Server;

    // 登陆
    @RequestMapping(value = ServiceApi.Login.LOGIN, method = RequestMethod.POST)
    public Envelope login(String datajson){
        return Server.login(datajson);
    }

    // 重置密码
    @RequestMapping(value = ServiceApi.Login.FOGETPASSWORD, method = RequestMethod.POST)
    public Envelope forgetPassword(String datajson){
        return super.saveEntity(datajson);
    }

    // 注册以及修改数据
    @RequestMapping(value = ServiceApi.Login.RIGISTER, method = RequestMethod.POST)
    public Envelope saveEntity(String datajson){
        return Server.Register(datajson);
    }

    // 注销
    @RequestMapping(value = ServiceApi.Login.DELETE, method = RequestMethod.GET)
    public Envelope deleteEntity(String id){
        return super.deleteEntity(id);
    }

}
